﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:expertInfo
	/// </summary>
	public partial class expertInfo
	{
		public expertInfo()
		{}
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("expertInfoId", "expertInfo");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int expertInfoId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from expertInfo");
            strSql.Append(" where expertInfoId=@expertInfoId");
            SqlParameter[] parameters = {
					new SqlParameter("@expertInfoId", SqlDbType.Int,4)
			};
            parameters[0].Value = expertInfoId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.expertInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into expertInfo(");
            strSql.Append("expertName,unit,contactway,expertMajor,expertStudyMajor,isUse,商务综合,变电一次,变电二次,输电线路,s10KV配电,安全工具,原材料,勘察,设计,施工,监理,配电,服务类,基建)");
            strSql.Append(" values (");
            strSql.Append("@expertName,@unit,@contactway,@expertMajor,@expertStudyMajor,@isUse,@商务综合,@变电一次,@变电二次,@输电线路,@s10KV配电,@安全工具,@原材料,@勘察,@设计,@施工,@监理,@配电,@服务类,@基建)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@expertName", SqlDbType.NVarChar,20),
					new SqlParameter("@unit", SqlDbType.NVarChar,20),
					new SqlParameter("@contactway", SqlDbType.VarChar,50),
					new SqlParameter("@expertMajor", SqlDbType.NVarChar,300),
					new SqlParameter("@expertStudyMajor", SqlDbType.NVarChar,50),
					new SqlParameter("@isUse", SqlDbType.Bit,1),
					new SqlParameter("@商务综合", SqlDbType.Bit,1),
					new SqlParameter("@变电一次", SqlDbType.Bit,1),
					new SqlParameter("@变电二次", SqlDbType.Bit,1),
					new SqlParameter("@输电线路", SqlDbType.Bit,1),
					new SqlParameter("@s10KV配电", SqlDbType.Bit,1),
					new SqlParameter("@安全工具", SqlDbType.Bit,1),
					new SqlParameter("@原材料", SqlDbType.Bit,1),
					new SqlParameter("@勘察", SqlDbType.Bit,1),
					new SqlParameter("@设计", SqlDbType.Bit,1),
					new SqlParameter("@施工", SqlDbType.Bit,1),
					new SqlParameter("@监理", SqlDbType.Bit,1),
					new SqlParameter("@配电", SqlDbType.Bit,1),
					new SqlParameter("@服务类", SqlDbType.Bit,1),
					new SqlParameter("@基建", SqlDbType.Bit,1)};
            parameters[0].Value = model.expertName;
            parameters[1].Value = model.unit;
            parameters[2].Value = model.contactway;
            parameters[3].Value = model.expertMajor;
            parameters[4].Value = model.expertStudyMajor;
            parameters[5].Value = model.isUse;
            parameters[6].Value = model.商务综合;
            parameters[7].Value = model.变电一次;
            parameters[8].Value = model.变电二次;
            parameters[9].Value = model.输电线路;
            parameters[10].Value = model.s10KV配电;
            parameters[11].Value = model.安全工具;
            parameters[12].Value = model.原材料;
            parameters[13].Value = model.勘察;
            parameters[14].Value = model.设计;
            parameters[15].Value = model.施工;
            parameters[16].Value = model.监理;
            parameters[17].Value = model.配电;
            parameters[18].Value = model.服务类;
            parameters[19].Value = model.基建;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.expertInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update expertInfo set ");
            strSql.Append("expertName=@expertName,");
            strSql.Append("unit=@unit,");
            strSql.Append("contactway=@contactway,");
            strSql.Append("expertMajor=@expertMajor,");
            strSql.Append("expertStudyMajor=@expertStudyMajor,");
            strSql.Append("isUse=@isUse,");
            strSql.Append("商务综合=@商务综合,");
            strSql.Append("变电一次=@变电一次,");
            strSql.Append("变电二次=@变电二次,");
            strSql.Append("输电线路=@输电线路,");
            strSql.Append("s10KV配电=@s10KV配电,");
            strSql.Append("安全工具=@安全工具,");
            strSql.Append("原材料=@原材料,");
            strSql.Append("勘察=@勘察,");
            strSql.Append("设计=@设计,");
            strSql.Append("施工=@施工,");
            strSql.Append("监理=@监理,");
            strSql.Append("配电=@配电,");
            strSql.Append("服务类=@服务类,");
            strSql.Append("基建=@基建");
            strSql.Append(" where expertInfoId=@expertInfoId");
            SqlParameter[] parameters = {
					new SqlParameter("@expertName", SqlDbType.NVarChar,20),
					new SqlParameter("@unit", SqlDbType.NVarChar,20),
					new SqlParameter("@contactway", SqlDbType.VarChar,50),
					new SqlParameter("@expertMajor", SqlDbType.NVarChar,300),
					new SqlParameter("@expertStudyMajor", SqlDbType.NVarChar,50),
					new SqlParameter("@isUse", SqlDbType.Bit,1),
					new SqlParameter("@商务综合", SqlDbType.Bit,1),
					new SqlParameter("@变电一次", SqlDbType.Bit,1),
					new SqlParameter("@变电二次", SqlDbType.Bit,1),
					new SqlParameter("@输电线路", SqlDbType.Bit,1),
					new SqlParameter("@s10KV配电", SqlDbType.Bit,1),
					new SqlParameter("@安全工具", SqlDbType.Bit,1),
					new SqlParameter("@原材料", SqlDbType.Bit,1),
					new SqlParameter("@勘察", SqlDbType.Bit,1),
					new SqlParameter("@设计", SqlDbType.Bit,1),
					new SqlParameter("@施工", SqlDbType.Bit,1),
					new SqlParameter("@监理", SqlDbType.Bit,1),
					new SqlParameter("@配电", SqlDbType.Bit,1),
					new SqlParameter("@服务类", SqlDbType.Bit,1),
					new SqlParameter("@基建", SqlDbType.Bit,1),
					new SqlParameter("@expertInfoId", SqlDbType.Int,4)};
            parameters[0].Value = model.expertName;
            parameters[1].Value = model.unit;
            parameters[2].Value = model.contactway;
            parameters[3].Value = model.expertMajor;
            parameters[4].Value = model.expertStudyMajor;
            parameters[5].Value = model.isUse;
            parameters[6].Value = model.商务综合;
            parameters[7].Value = model.变电一次;
            parameters[8].Value = model.变电二次;
            parameters[9].Value = model.输电线路;
            parameters[10].Value = model.s10KV配电;
            parameters[11].Value = model.安全工具;
            parameters[12].Value = model.原材料;
            parameters[13].Value = model.勘察;
            parameters[14].Value = model.设计;
            parameters[15].Value = model.施工;
            parameters[16].Value = model.监理;
            parameters[17].Value = model.配电;
            parameters[18].Value = model.服务类;
            parameters[19].Value = model.基建;
            parameters[20].Value = model.expertInfoId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int expertInfoId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from expertInfo ");
            strSql.Append(" where expertInfoId=@expertInfoId");
            SqlParameter[] parameters = {
					new SqlParameter("@expertInfoId", SqlDbType.Int,4)
			};
            parameters[0].Value = expertInfoId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string expertInfoIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from expertInfo ");
            strSql.Append(" where expertInfoId in (" + expertInfoIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.expertInfo GetModel(int expertInfoId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 expertInfoId,expertName,unit,contactway,expertMajor,expertStudyMajor,isUse,商务综合,变电一次,变电二次,输电线路,s10KV配电,安全工具,原材料,勘察,设计,施工,监理,配电,服务类,基建 from expertInfo ");
            strSql.Append(" where expertInfoId=@expertInfoId");
            SqlParameter[] parameters = {
					new SqlParameter("@expertInfoId", SqlDbType.Int,4)
			};
            parameters[0].Value = expertInfoId;

            Maticsoft.Model.expertInfo model = new Maticsoft.Model.expertInfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.expertInfo DataRowToModel(DataRow row)
        {
            Maticsoft.Model.expertInfo model = new Maticsoft.Model.expertInfo();
            if (row != null)
            {
                if (row["expertInfoId"] != null && row["expertInfoId"].ToString() != "")
                {
                    model.expertInfoId = int.Parse(row["expertInfoId"].ToString());
                }
                if (row["expertName"] != null)
                {
                    model.expertName = row["expertName"].ToString();
                }
                if (row["unit"] != null)
                {
                    model.unit = row["unit"].ToString();
                }
                if (row["contactway"] != null)
                {
                    model.contactway = row["contactway"].ToString();
                }
                if (row["expertMajor"] != null)
                {
                    model.expertMajor = row["expertMajor"].ToString();
                }
                if (row["expertStudyMajor"] != null)
                {
                    model.expertStudyMajor = row["expertStudyMajor"].ToString();
                }
                if (row["isUse"] != null && row["isUse"].ToString() != "")
                {
                    if ((row["isUse"].ToString() == "1") || (row["isUse"].ToString().ToLower() == "true"))
                    {
                        model.isUse = true;
                    }
                    else
                    {
                        model.isUse = false;
                    }
                }
                if (row["商务综合"] != null && row["商务综合"].ToString() != "")
                {
                    if ((row["商务综合"].ToString() == "1") || (row["商务综合"].ToString().ToLower() == "true"))
                    {
                        model.商务综合 = true;
                    }
                    else
                    {
                        model.商务综合 = false;
                    }
                }
                if (row["变电一次"] != null && row["变电一次"].ToString() != "")
                {
                    if ((row["变电一次"].ToString() == "1") || (row["变电一次"].ToString().ToLower() == "true"))
                    {
                        model.变电一次 = true;
                    }
                    else
                    {
                        model.变电一次 = false;
                    }
                }
                if (row["变电二次"] != null && row["变电二次"].ToString() != "")
                {
                    if ((row["变电二次"].ToString() == "1") || (row["变电二次"].ToString().ToLower() == "true"))
                    {
                        model.变电二次 = true;
                    }
                    else
                    {
                        model.变电二次 = false;
                    }
                }
                if (row["输电线路"] != null && row["输电线路"].ToString() != "")
                {
                    if ((row["输电线路"].ToString() == "1") || (row["输电线路"].ToString().ToLower() == "true"))
                    {
                        model.输电线路 = true;
                    }
                    else
                    {
                        model.输电线路 = false;
                    }
                }
                if (row["s10KV配电"] != null && row["s10KV配电"].ToString() != "")
                {
                    if ((row["s10KV配电"].ToString() == "1") || (row["s10KV配电"].ToString().ToLower() == "true"))
                    {
                        model.s10KV配电 = true;
                    }
                    else
                    {
                        model.s10KV配电 = false;
                    }
                }
                if (row["安全工具"] != null && row["安全工具"].ToString() != "")
                {
                    if ((row["安全工具"].ToString() == "1") || (row["安全工具"].ToString().ToLower() == "true"))
                    {
                        model.安全工具 = true;
                    }
                    else
                    {
                        model.安全工具 = false;
                    }
                }
                if (row["原材料"] != null && row["原材料"].ToString() != "")
                {
                    if ((row["原材料"].ToString() == "1") || (row["原材料"].ToString().ToLower() == "true"))
                    {
                        model.原材料 = true;
                    }
                    else
                    {
                        model.原材料 = false;
                    }
                }
                if (row["勘察"] != null && row["勘察"].ToString() != "")
                {
                    if ((row["勘察"].ToString() == "1") || (row["勘察"].ToString().ToLower() == "true"))
                    {
                        model.勘察 = true;
                    }
                    else
                    {
                        model.勘察 = false;
                    }
                }
                if (row["设计"] != null && row["设计"].ToString() != "")
                {
                    if ((row["设计"].ToString() == "1") || (row["设计"].ToString().ToLower() == "true"))
                    {
                        model.设计 = true;
                    }
                    else
                    {
                        model.设计 = false;
                    }
                }
                if (row["施工"] != null && row["施工"].ToString() != "")
                {
                    if ((row["施工"].ToString() == "1") || (row["施工"].ToString().ToLower() == "true"))
                    {
                        model.施工 = true;
                    }
                    else
                    {
                        model.施工 = false;
                    }
                }
                if (row["监理"] != null && row["监理"].ToString() != "")
                {
                    if ((row["监理"].ToString() == "1") || (row["监理"].ToString().ToLower() == "true"))
                    {
                        model.监理 = true;
                    }
                    else
                    {
                        model.监理 = false;
                    }
                }
                if (row["配电"] != null && row["配电"].ToString() != "")
                {
                    if ((row["配电"].ToString() == "1") || (row["配电"].ToString().ToLower() == "true"))
                    {
                        model.配电 = true;
                    }
                    else
                    {
                        model.配电 = false;
                    }
                }
                if (row["服务类"] != null && row["服务类"].ToString() != "")
                {
                    if ((row["服务类"].ToString() == "1") || (row["服务类"].ToString().ToLower() == "true"))
                    {
                        model.服务类 = true;
                    }
                    else
                    {
                        model.服务类 = false;
                    }
                }
                if (row["基建"] != null && row["基建"].ToString() != "")
                {
                    if ((row["基建"].ToString() == "1") || (row["基建"].ToString().ToLower() == "true"))
                    {
                        model.基建 = true;
                    }
                    else
                    {
                        model.基建 = false;
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select expertInfoId,expertName,unit,contactway,expertMajor,expertStudyMajor,isUse,商务综合,变电一次,变电二次,输电线路,s10KV配电,安全工具,原材料,勘察,设计,施工,监理,配电,服务类,基建 ");
            strSql.Append(" FROM expertInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" expertInfoId,expertName,unit,contactway,expertMajor,expertStudyMajor,isUse,商务综合,变电一次,变电二次,输电线路,s10KV配电,安全工具,原材料,勘察,设计,施工,监理,配电,服务类,基建 ");
            strSql.Append(" FROM expertInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM expertInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.expertInfoId desc");
            }
            strSql.Append(")AS Row, T.*  from expertInfo T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "expertInfo";
            parameters[1].Value = "expertInfoId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
		
		#region  ExtensionMethod
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateIsUse(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update expertInfo set isUse = 0 ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
		#endregion  ExtensionMethod
	}
}

